import 'package:flutter/material.dart';
import '../../helper/channelHelper.dart';
import '../../helper/Helper.dart';
import '../../helper/cacheHelper.dart';
import '../../helper/global_config.dart';
import '../../helper/routeHelper.dart';
import '../../helper/uidata.dart';
import '../../model/security_check.dart';
import '../../model/user.dart';
import '../../pages/security/securitycheck_add.dart';
import '../../pages/security/securitycheck_info.dart';
import '../../widgets/IconWidget.dart';
import '../../widgets/dialogWidget.dart';
import '../../widgets/inputWidget.dart';

import 'security_details.dart';

class SecurityHelper {
  static Widget SecurityCheckCard3(
      BuildContext context, SecurityCheck record, RefreshCallback refrush) {
    var u1 = CacheHelper.GetUser(record.UserId);

    return Column(children: [
      Container(
        key: Key(record.ID.toString()),
        // margin: const EdgeInsets.only(top: 5.0, bottom: 5.0),
        //shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
        color: GlobalConfig.cardBackgroundColor,
        child: ListTile(
          onTap: () {
            //
            if (record.UserId == UIData.CurrentUser!.Guid) {
              RouteHelper.ShowPage(
                  context, SecurityCheckAddPage(record, () => {}));
            } else {
              RouteHelper.ShowPage(context, SecurityCheckPage(record));
            }
          },
          onLongPress: () {
            if (record.State > 0) {
              ChannelHelper.showToast("已填写，不能删除！");
              return;
            }

            if (!Helper.UserPB(record.UserId)) {
              ChannelHelper.showToast("只能删除自己创建的！");
              return;
            }

            showDialog(
              context: context,
              builder: (BuildContext context) {
                if (u1 != null && u1.Guid != record.UserId.toLowerCase()) {
                  return DialogWidget.getAlert(context, "提示", "只能删除自己上传的记录");
                } else {
                  return DialogWidget.getDialog(
                      context, "删除记录", "点击确定键将删除该条记录！     " + record.CreateTime,
                      () {
                    SecurityCheck.Delete(record);
                    refrush();
                  });
                }
              },
            );
          },
          subtitle: Text(Helper.DateTimeFormat(record.CreateTime)),
          leading: IconWidget.CheckImage(),
          trailing: Text(
            u1.Name,
          ),
          title: Text(record.Title),
        ),
      ),
      InputWidget.getDivider()
    ]);
  }

  static bool IfGuanLi(User u1) {
    //  return true;
    if (u1.Authority.contains("安全管理")) return true;
    if (u1.Authority.contains("部门领导")) return true;
    //if(s1.BMIfOK && s1.DCIfOK && s1.GCBIfOK && s1.LDIfOK && DcZby(u1)&&s1.State==3)
    //return true;
    return false;
  }

  static List<String> STypeList() {
    var xx = <String>[];
    xx.add("专项检查");
    xx.add("定期检查");
    return xx;
  }

  static List<String> RegionList() {
    var xx = <String>[];
    xx.add("成都办公区域");
    xx.add("坝上办公区域");
    xx.add("库区巡查");
    xx.add("外委施工监管");
    return xx;
  }

  static List<String> ContentList(String region) {
    var x1 = ['消防', '水情系统', '电气设备', '用电安全', '备品备件', '办公环境安全'];
    var x2 = ['消防', '水情系统', '电气设备', '用电安全', '备品备件', '办公环境安全'];
    var x3 = ['地质灾害', '船艇码头', '库区环境', '危化品', '船员值班室用电'];
    var x4 = ['用电安全', '高空作业', '临水安全', '规范操作', '安全防护'];

    if (region == "库区巡查") return x3.toList();
    if (region == "外委施工监管") return x4.toList();
    if (region == "坝上办公区域") return x2.toList();

    return x1.toList();
  }
}
